Programming using Arduino Uno

Our mentor gave us the following things with an ultrasonic sensor and we were asked to program using and measuring the distance such that after certain distance the Led light turns 'on' and 'off'.

items

Firstly I used the respective jumper wires to connect the Arduino UNO with the sensors, leds and resistors. The VCC and Gnd of the sensor must be connected to the VCC and Gnd of the Arduino board. The trigger pin of the sensor was connected to Digital pin numer 12 of the Arduino; EchoPin to 13; Led1 in 6; Led2 in 7;

The connections look something like the image given below;

ultrasonic sensors

For better understanding of the codes and the connections, I went through lots of videos and some of the tutorials that helped me progress with my successfull application of the programming and the successful connections are given below

Programming

Open the Arduino IDE and make sure you chose the port and the programmer before moving on with the coding. For the codes, firstly we have declare the output and input devices, their pin number and after that we have to create a loop in which you use 'if' and 'else' codes to make a condition for the leds to blink after certain distance is sensed from a given distance.

The code that I used for the measurement and the conditions for leds getting turned on can be seen in the following image.

code code

After verification and zero errors, I uploaded the program and I put a condition where red Led will turn on from a distance of 10cm and the yellow Led will turn off if motion is sensed more than 20 cm. The following video shows me checking whether the uploaded program works or now,

With the Leds lighting up with the given conditions, the programming is a success and since it was the first time that I successfully programmed something, it is a nice feeling of satisfaction for a guy like me having less or no electronics background.